package com.hkfrich.system.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkfrich.system.domain.SysRole;
import com.hkfrich.system.domain.SysRoleMenu;
import com.hkfrich.system.mapper.SysRoleMenuMapper;
import com.hkfrich.system.service.SysRoleMenuService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * 角色菜单关联Service业务层处理
 * 
 * @author _Heishuai
 * @date 2022-09-20 20:54:13
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {

    @Resource
    private SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public int insertRoleMenu(SysRole sysRole) {
        int rows = 1;
        // 新增用户与角色管理
        List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
        for (Long menuId : sysRole.getMenuIds())
        {
            SysRoleMenu rm = new SysRoleMenu();
            rm.setRoleId(sysRole.getRoleId());
            rm.setMenuId(menuId);
            list.add(rm);
        }
        if (list.size() > 0)
        {
            rows = sysRoleMenuMapper.batchRoleMenu(list);
        }
        return rows;
    }
}
